
<link href="<?php echo base_url();?>assets/css/jquery-ui.css" rel="stylesheet">
<script src="<?php echo base_url();?>assets/js/jquery-ui.js"></script>

<script>
	$(function() {
    	$( "#tabs" ).tabs().addClass( "ui-tabs-vertical ui-helper-clearfix" );
    	$( "#tabs li" ).removeClass( "ui-corner-top" ).addClass( "ui-corner-left" );
  	});
</script>
<style>
  .ui-tabs-vertical { width: 83em; }
  .ui-tabs-vertical .ui-tabs-nav {float: left; border-right: 1px solid #DDDDDD; padding:10px 0; min-height:300px; display: block; width:170px; }
  .ui-tabs-vertical .ui-tabs-nav li { clear: left; width: 100%; border-bottom-width: 1px !important; border-right-width: 0 !important; margin: 0 -1px .2em 0; }
  .ui-tabs-vertical .ui-tabs-nav li a { display:block; }
  .ui-tabs-vertical .ui-tabs-nav li.ui-tabs-active { padding-bottom: 0; padding-right: .1em; border-right-width: 1px; border-right-width: 1px; }
  .ui-tabs-vertical .ui-tabs-panel { padding: 1em; float: left; width: 68em;}
  #tabs .control-label{font-weight:bold;}
  #tabs .nav a{font-weight:bold;}
  .table tbody .right {text-align: right;}
  #tabs .control-group {margin-bottom: 10px;}
  #tabs hr {margin: 10px 0;}
  #order-cancel {padding-left: 180px;}
</style>

      <!-- Begin page content -->
      <div class="container content-body">
      	<div class="page-header" style="position:relative;">
  			<h3>Orders</h3>  		
		</div>

		<div id="message"></div>
		
		<div id="tabs">
			<div class="row">
				<div class="span2" >
					<ul class="nav nav-tabs" id="myTab">
						<li><a href="#tabs-order">Order Details</a> </li> 
						<li><a href="#tabs-payment">Payment Details</a></li>
						<li><a href="#tabs-shipping">Shipping Details </a></li> 
						<li><a href="#tabs-products">Products</a></li> 
						<li><a href="#tabs-history">History</a></li> 
					</ul>
				</div>
				
                <div class="tab-content">
				<div id="tabs-order" class="form-horizontal tab-pane">
                	<div class="control-group">
						<label class="control-label" for="order_id">Order Code</label>
						<div class="controls">
							<p><?php echo $order->order_cid; ?></p>
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="order_id">Order ID</label>
						<div class="controls">
							<p><?php echo $order->order_id; ?></p>
						</div>
					</div>
			        <hr>
			        <div class="control-group">
						<label class="control-label" for="invoice_no">Invoice No</label>
						<div class="controls">
			            	<p><?php echo $order->invoice_no; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="customer">Customer</label>
						<div class="controls">
			            	<p><?php echo $order->firstname; ?> <?php echo $order->lastname; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="email">Email</label>
						<div class="controls">
							<p><?php echo $order->email; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="telephone">Telephone</label>
						<div class="controls">
							<p><?php echo $order->telephone; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="total">Total</label>
						<div class="controls">
							<p><?php echo 'Rp '. number_format($order->total); ?></p>		
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="order_status_id">Order Status</label>
						<div class="controls">
                        	<?php $get_status = $this->order_model->get_order_status(); ?>
                            <?php foreach($get_status as $status){ ?> 
								<?php if($status->order_status_id == $order->order_status_id){ ?>
                                	<p><?php echo $status->name ?></p> 
                                <?php } ?>
							<?php } ?>
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="date_added">Date Add</label>
						<div class="controls">
			            	<p><?php echo $order->date_added; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="date_modified">Date Modified</label>
						<div class="controls">
							<p><?php echo $order->date_modified; ?></p>	
						</div>
					</div>
				</div>
				
				<div id="tabs-payment" class="form-horizontal tab-pane" style="display:block;">
					<div class="control-group">
						<label class="control-label" for="payment_firstname">First Name</label>
						<div class="controls">
							<p><?php echo $order->payment_firstname; ?></p>
						</div>
					</div>
			        <hr>
			        <div class="control-group">
						<label class="control-label" for="payment_lastname">Last Name</label>
						<div class="controls">
			            	<p><?php echo $order->payment_lastname; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_address_1">Address 1</label>
						<div class="controls">
			            	<p><?php echo $order->payment_address_1; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_address_2">Address 2</label>
						<div class="controls">
							<p><?php echo $order->payment_address_2; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_phone">Telephone</label>
						<div class="controls">
							<p><?php echo $order->payment_phone; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_city">City</label>
						<div class="controls">
							<p><?php echo $order->payment_city; ?></p>		
						</div>
					</div>
			                        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_postcode">Post Code</label>
						<div class="controls">
							<p><?php echo $order->payment_postcode; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_zone">Region/State</label>
						<div class="controls">
			            	<p><?php echo $order->payment_zone; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="payment_country">Country</label>
						<div class="controls">
							<p><?php echo $order->payment_country; ?></p>	
						</div>
					</div>
					<hr>
					<div class="control-group">
						<label class="control-label" for="payment_method">Payment Method</label>
						<div class="controls">
							<?php if($order->payment_method == 1){ ?>
								<p>Cash On Delivery</p>
							<?php }else if($order->payment_method == 2){ ?>
								<p>Transfer Bank</p>
							<?php } ?>
						</div>
					</div>
                    <hr>
					<div class="control-group">
						<label class="control-label" for="payment_status_id">Payment Status</label>
						<div class="controls">
                        	<?php $get_pay = $this->order_model->get_payment_status(); ?>
                            <?php foreach($get_pay as $status_pay){ ?> 
								<?php if($status_pay->payment_status_id == $order->payment_status_id){ ?>
                                	<p><?php echo $status_pay->name ?></p> 
                                <?php } ?>
							<?php } ?>
						</div>
					</div>
				</div>
				
				<div id="tabs-shipping" class="form-horizontal tab-pane" style="display:block;">
					<div class="control-group">
						<label class="control-label" for="shipping_firstname">First Name</label>
						<div class="controls">
							<p><?php echo $order->shipping_firstname; ?></p>
						</div>
					</div>
			        <hr>
			        <div class="control-group">
						<label class="control-label" for="shipping_lastname">Last Name</label>
						<div class="controls">
			            	<p><?php echo $order->shipping_lastname; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_address_1">Address 1</label>
						<div class="controls">
			            	<p><?php echo $order->shipping_address_1; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_address_2">Address 2</label>
						<div class="controls">
							<p><?php echo $order->shipping_address_2; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_city">City:</label>
						<div class="controls">
							<p><?php echo $order->shipping_city; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_postcode">Post Code</label>
						<div class="controls">
							<p><?php echo $order->shipping_postcode; ?></p>		
						</div>
					</div>
			                        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_zone">Region/State</label>
						<div class="controls">
							<p><?php echo $order->shipping_zone; ?></p>	
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_country">Country</label>
						<div class="controls">
			            	<p><?php echo $order->shipping_country; ?></p>                
						</div>
					</div>
			        <hr>
					<div class="control-group">
						<label class="control-label" for="shipping_method">Shipping Method</label>
						<div class="controls">
							<?php $order_shipping = $this->order_model->get_shipping_by_order($order->order_id) ?>
							<?php foreach($order_shipping as $shipping){ ?>
                                <?php $get_product_by_id = $this->order_model->get_product_by_id($shipping->product_id); ?>
                                <?php if($shipping->shipping_method == '0'){ ?>
									<p>(Product : <?php echo $get_product_by_id->product_name; ?>) -- 
								<?php }else{ ?>
									<p>(Product : <?php echo $get_product_by_id->product_name; ?>) <?php echo $shipping->shipping_method; ?> : <?php echo 'Rp '. number_format($shipping->price); ?></p>
	                            <?php } ?>
                            <?php } ?>		
						</div>
					</div>
				</div>
				
				<div id="tabs-products" class="form-horizontal tab-pane" style="display:block;">
					<table class="table table-bordered ">
						<thead>
							<tr style="background:#E2E2E2;">
								<th>Product Name</th>
								<th class="right">Quantity</th>
								<th class="right">Unit Price</th>
								<th class="right">Total</th>
							</tr>
						</thead>
						<tbody>
							<?php $order_product = $this->order_model->get_order_product_by_order($order->order_id); ?>
							<?php foreach ($order_product as $product){ ?>
							<tr>
								<td><?php echo $product->name; ?><br>
       								<?php $opt = $this->order_model->get_order_option_by_order_product($product->order_product_id);
       									  if($opt != NULL){
       									  	echo $opt->option_name.' : '.$opt->option_value;
       									  } 
       								?>
                                </td>
								<td class="right"><?php echo $product->quantity; ?></td>
								<td class="right"><?php echo 'Rp '.number_format($product->price); ?></td>
								<td class="right"><?php echo 'Rp '.number_format($product->subtotal); ?></td>
							</tr>
							<?php } ?>
							<?php $sum = $this->order_model->get_order_total($order->order_id); ?>
							<tr>
								<td colspan="3" class="right">Sub-Total</td>
                                <?php foreach ($sum as $keys => $subtotal){ ?>
									<?php if($subtotal->code == 'total'){ ?>
                                    <td class="right"><?php echo 'Rp '.number_format($s = $subtotal->value) ?></td>
                                    <?php } ?>
                                <?php } ?>
							</tr>
							<tr>
								<td colspan="3" class="right">Total Shipping</td>
								<?php foreach ($sum as $keys => $subtotal){ ?>
									<?php if($subtotal->code == 'total_shipping'){ ?>
                                    <td class="right"><?php echo 'Rp '.number_format($sh = $subtotal->value) ?></td>
                                    <?php } ?>
                                <?php } ?>
							</tr>
                            <tr>
								<td colspan="3" class="right">Tax</td>
								<?php foreach ($sum as $keys => $subtotal){ ?>
									<?php if($subtotal->code == 'tax'){ ?>
                                    <td class="right"><?php echo 'Rp '.number_format($tx = $subtotal->value) ?></td>
                                    <?php } ?>
                                <?php } ?>
							</tr>
                            <?php $sum_total = $this->order_model->sum_total($order->order_id); ?>
							<tr>
								<td colspan="3" class="right">Total</td>
                                <?php foreach ($sum_total as $total){ ?>
								<td class="right"><?php echo 'Rp '.number_format($total->value); ?></td>
                                <?php } ?>
							</tr>
						</tbody>
					</table>
				</div>
				
				<div id="tabs-history" class="form-horizontal tab-pane" style="display:block;">
					<?php $get_history = $this->order_model->get_history($order->order_id); ?>
                	<table class="table table-bordered ">
						<thead>
							<tr style="background:#E2E2E2;">
								<th width="160px;">Date Added</th>
								<th width="160px;">Order Status</th>
                                <th width="160px;">Payment Status</th>
								<th>Comment</th>
							</tr>
						</thead>
                        <tbody>
                        	<?php foreach ($get_history as $row): ?>
                            <tr>
                            	<td><?php echo $row->date_added ?></td>
                                <?php $get_status = $this->order_model->get_order_status(); ?>
                            	<?php foreach($get_status as $status){ ?> 
									<?php if($status->order_status_id == $row->order_status_id){ ?>
                                        <td><?php echo $status->name ?></td> 
                                    <?php } ?>
								<?php } ?>
                                <?php $get_pay = $this->order_model->get_payment_status(); ?>
                           		<?php foreach($get_pay as $status_pay){ ?> 
									<?php if($status_pay->payment_status_id == $row->payment_status_id){ ?>
                                        <td><?php echo $status_pay->name ?></td> 
                                    <?php } ?>
								<?php } ?>
                                <?php if($row->comment == NULL || empty($row->comment)) {?>
									<td><?php echo '-----' ?></td>
								<?php }else{?>
                                	<td><?php echo $row->comment ?></td>
                                <?php } ?>
                            </tr>
                        	<?php endforeach; ?> 
                        </tbody>
                    </table>
                	<?php echo form_open('order/status/'. $order->order_id,'class ="form-horizontal" ');?>
                	<div class="control-group">
						<label class="control-label" for="order_status_id">Order Status</label>
						<div class="controls">
                        	<?php $get_status = $this->order_model->get_order_status(); ?>
                            <select name="order_status_id">
                            <?php foreach($get_status as $status){ ?> 
								<option value="<?php echo $status->order_status_id ?>" <?php if($status->order_status_id == $order->order_status_id) echo ("selected=\"selected\"");?>>
                                	<?php echo $status->name ?></option>
							<?php } ?>
            				</select>
						</div>
					</div>
                    <hr>
                    <div class="control-group">
						<label class="control-label" for="payment_status_id">Payment Status</label>
						<div class="controls">
                        	<?php $get_pay = $this->order_model->get_payment_status(); ?>
                            <select name="payment_status_id">
                            <?php foreach($get_pay as $status_pay){ ?> 
								<option value="<?php echo $status_pay->payment_status_id ?>" <?php if($status_pay->payment_status_id == $order->payment_status_id) echo ("selected=\"selected\"");?>>
                                	<?php echo $status_pay->name ?></option>
							<?php } ?>
            				</select>
						</div>
					</div>
                    <hr>
					<div class="control-group">
						<label class="control-label" for="comment">Comment</label>
						<div class="controls">
                            <textarea name="comment" cols="40" rows="8" style="width: 98%"><?php echo set_value('comment', $order->comment); ?></textarea>	
						</div>
					</div>
                    <div>
                    	<input class="btn btn-primary" id="submit" type="submit" value="Save Change" />
                    </div>
                	<?php echo form_close(); ?>
				</div>
				</div>
			</div>
		</div>
		<div class="form-actions" id="order-cancel">
			<a href="<?php echo site_url('order/index'); ?>" class="btn" id="cancel" type="button" name="cancel" value="Back">Cancel</a> 
        </div>
      </div>